<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        ul,ol{
            list-style: none;
        }
        .lunbo{
            position: relative;
            width: 626px;
            height: 380px;
            border: 1px solid black;
            margin: 20px auto;
        }
        .lunbo .pic li{
            position:absolute;
            left: 0;
            top: 0;
            width: 626px;
            height: 386px;
            object-fit: cover;
            display: none;
        }
        .lunbo .pic .current{
            display: block;
        }
        /* 按钮 */
        .lunbo .btn a {
            position: absolute;
            top: 50%;
            width: 40px;
            height: 40px;
            margin-top: -20px;
            background-color: rgb(61, 59, 187);
            font: 20px/40px "宋体";
            text-align: center;
            font-weight: bold;
            color: cornsilk;
            text-decoration: none;
        }
        .lunbo .btn .leftbtn{
        left: 20px;
        }
        .lunbo .btn .rightbtn{
        right: 20px;
        }
        .lunbo .btn a:hover{
            background-color: cyan;
        }
        /* 下标 */
        .lunbo .sub{
            position: absolute;
            left: 50px;
            bottom: 50px;
            width: 300px;
        }
        .lunbo .sub li{
            float: left;
            width: 20px;
            height: 20px;
            background-color: rgb(138, 138, 138);
            margin-right:20px;
            font: 12px/20px "微软雅黑";
            text-align: center;
            color: darkgray;
            cursor: pointer;
        }
        .lunbo .sub .current{
            background-color: white;
        }
    </style>
</head>
<body>
    <!-- 轮播图大结构 -->
    <div id="lunbo" class="lunbo">
        <!-- 图片部分 -->
        <ul class="pic"  id="pic">
            <li class="current"><img src="滚动图1.jpg" alt=""></li>
            <li><img src="滚动图2.jpg" alt=""></li>
            <li><img src="滚动图3.jpg" alt=""></li>
            <li><img src="滚动图4.jpg" alt=""></li>
        </ul>
        <!-- 按钮 -->
        <div class="btn" id="btn">
            <a href="javascript:;" class="leftbtn" id="leftbtn">&lt;</a>
            <a href="javascript:;" class="rightbtn" id="rightbtn">&gt;</a>
        </div>
        <!-- 小圆点 -->
        <ol class="sub " id = "sub">
            <li class="current">1</li>
            <li>2</li>
            <li>3</li>
            <li>4</li>
            <li>5</li>
            <li>6</li>
        </ol>
    </div>
    <script>
        var lunbo = document.getElementById("lunbo");
        var ol = document.getElementById("sub");
        var ul = document.getElementById("pic");
        var btn = document.getElementById("btn");
        var olLis = ol.children;
        var leftbtn = document.getElementById("leftbtn");
        var rightbtn = document.getElementById("rightbtn");
        var ulLis = ul.children;
        var idx = 0;
        rightbtn.onclick = rightHandle;
        console.log(ol);
        console.log(ul);
        console.log(lunbo);
        leftbtn.onclick = function () {
            idx-- ;
            if (idx < 0){
                idx = ulLis.length - 1;
            };
            change();
        };
        for (var i = 0 ; i < olLis.length; i++) {
            olLis[i].index = i;
            olLis[i].onclick = function (){
                idx = this.index;
                change();
            };
        }
        var timer;
        timer = setInterval(rightHandle,3000);
        lunbo.onmouseover = function () {
            clearInterval(timer);
        };
        lunbo.onmouseout = function () {
            timer = setInterval(rightHandle,3000);
        };
        function rightHandle() {
            idx++;
            if (idx > ulLis.length - 1) {
                idx = 0;
            }
            change();
        };
        function change() {
            for (var i = 0 ; i < ulLis.length ; i++) {
                ulLis[i].className = "";
                olLis[i].className = "";
            }
            ulLis[idx].className = "current";
            olLis[idx].className = "current";
        }
    </script>
</body>
</html>